public class Solution {
    public boolean canPartition(int[] nums) {
        int sum = 0;
        int n = nums.length;
        for(int i = 0; i < n; i++){
            sum += nums[i];
        }
        if(sum % 2 == 1 || n < 2){
            return false;
        }
        boolean[] dp = new boolean[sum/2 + 1];
        dp[0] = true;
        for(int i = 1; i <= n; i++){
            int num = nums[i - 1];
            for(int j = sum / 2; j >= num; j--){
                dp[j] = dp[j] || dp[j - num];
            }

        }
        return dp[sum/2];

    }
}
